package com.crm.system.controller.productManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.common.Dictionary;
import com.crm.model.qo.productManager.CustomerMemberCardServingQO;
import com.crm.system.service.productManager.CustomerMemberCardServingService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;


/**
 * 会员卡服务项管理
 * @author luojie
 * @date 2021/4/12 15:24
 */
@RestController
@RequestMapping("/customerMemberCardServing")
public class CustomerMemberCardServingController {

    @Autowired
    private CustomerMemberCardServingService customerMemberCardServingService;


    /***
     * @Description: 查询会员卡服务接口
     * @Param: parentId 父id
     * @Author: luojie
     * @Date: 2021/4/12 16:37
     */
    @GetMapping("/selectMemberCardServingDropDownList")
    public DataResponse selectServiceTypeDropDownList(HttpServletRequest request,
                                                      @RequestParam(value="parentId",required = true) String parentId,
                                                      @RequestParam(value="memberProductRelationId",required = false) String memberProductRelationId){
        List<JSONObject> dictionaryList = customerMemberCardServingService.selectMemberCardServingDropDownList(parentId,memberProductRelationId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),dictionaryList);
    }

    /***
     * @Description:保存会员卡服务配置项
     * @Param:CustomerMemberCardServingQO 保存会员卡服务配置项类
     * @Author: luojie
     * @Date: 2021/4/13 10:28
     */
    @PostMapping("/addMemberCardServing")
    public DataResponse addMemberCardServing(HttpServletRequest request,@RequestBody CustomerMemberCardServingQO customerMemberCardServingQO){
        Boolean result = customerMemberCardServingService.addMemberCardServing(customerMemberCardServingQO);
        if(result){
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        }else {
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /***
     * @Description:删除会员服务产品和服务项关系表数据
     * @Param: memberProductRelationId 会员服务产品和服务项关系表主键
     * @Author: luojie
     * @Date: 2021/4/13 13:48
     */
    @GetMapping("/deleteMemberCardServingById")
    public DataResponse deleteMemberCardServingById(HttpServletRequest request,@RequestParam(value="memberProductRelationId",required = true) String memberProductRelationId){
        Boolean result = customerMemberCardServingService.deleteMemberCardServingById(memberProductRelationId);
        if(result){
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        }else {
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /***
     * @Description:添加服务明细
     * @Param:object 参数对象
     * @Author: luojie
     * @Date: 2021/4/13 16:54
     */
    @PostMapping("/addServingDetail")
    public DataResponse addServingDetail(HttpServletRequest request,
                                        @RequestBody JSONObject object){
        //字典表中的父id
        String parentId = object.getString("parentId");
        //服务名称
        String name = object.getString("name");
        if(!StringUtils.isBlank(parentId)&&!StringUtils.isBlank(name)){
            String result = customerMemberCardServingService.addServingDetail(parentId,name);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),result);
        }else {
            return new DhResponse(ResponseCodeEnum.PARAMETER_ERROR.getResponseCode());
        }
    }

}
